package arithmetic.LeetCode;

import org.junit.jupiter.api.Test;

/**
 * @author jiangfeng on 2022/6/27
 */
public class Jump {

    @Test
    public void test(){
        System.out.println(canJump(new int[]{2,3,1,1,4}));
    }

    public boolean canJump(int[] nums) {
        int max = 0;
        for(int i =0;i<nums.length;i++){
            if(i>max){
                return false;
            }

            max = Math.max(nums[i]+i,max);
            if(max>=nums.length-1){
                return true;
            }
        }
        return true;

    }
}
